
#ifndef MCPOLYGONIZER_H
#define MCPOLYGONIZER_H

#include "typedefs.h"
#include "polygonize.h"

#include <vector>
#include <map>
#include <cmath>
#include <fstream>

class MCPolygonizer {
   
public:
   MCPolygonizer(const int& nvX, const int& nvY, const int& nvZ);
   ~MCPolygonizer();
   
   void polygonize(const vector<Point3> &grid, const vector<Number> &fvalues);
   void export2off(char *filename);
   
private:
   inline int getIdX(int i) { return i+1; } // returns the id of cube on right of i
   inline int getIdY(int i) { return i+nvoxelsX; }
   inline int getIdZ(int i) { return i+nvoxelsX*nvoxelsY; }
   inline int getCubeId(int i, int j, int k) { return (nvoxelsX*nvoxelsY*k + nvoxelsX*j + i); }
   void setCubeValues(int , GRIDCELL &, const vector<Point3> &, const vector<Number> &);
   
   int checkNewVertex (int i, int j, int k, int edge, int newCell[]);
   
private:
   int                     nvoxelsX, nvoxelsY, nvoxelsZ; // number of voxels on each coordinate (not cubes)
   std::vector<Point3>     vertices; // the isosurface's vertices
   std::vector<int>        facets; // the isosurface's facets
   std::map <int, int*>    CrossingCells;
};

#endif
